﻿using System;

namespace Needle.DevToolkit.Traits
{
    [Serializable]
    internal class Item : IItem
    {
        public virtual T GetTrait<T>()
            where T : class
        {
            return this as T;
        }

        public bool TryGetTrait<T>(out T props)
            where T : class
        {
            props = GetTrait<T>();
            return props != null;
        }

        public virtual void Accept(IItemVisitor visitor)
        {
            visitor.Visit(this);
        }


        public bool HasTrait<T>()   
            where T : class
        {
            return GetTrait<T>() != null;
        }
    }
}
